<%-- 
    Document   : uploadTorrent
    Created on : Nov 22, 2012, 2:34:50 PM
    Author     : Hiro
--%>

<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.cfg.AnnotationConfiguration"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="Trackertag" uri="/WEB-INF/tlds/TrackerTag_library" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <LINK REL=StyleSheet HREF="..\style\style.css" TYPE="text/css" MEDIA=screen>
        <title>Upload Torrent</title>
    </head>
    <body>
        <%
            Boolean isLogin = false;
            Cookie[] ck = request.getCookies();
            if (ck != null) {
                for (int i = 0; i < ck.length; i++) {
                    if ("userId".equals(ck[i].getName())) { //Finding Username Cookie                
                        i = ck.length;
                        isLogin = true;
                    }
                }

            }
            if (isLogin == false) {
                response.sendRedirect("login.jsp");
                return;
            }
        %>
        <jsp:include page="navigation.jsp" />
        <div class="center-form">
            <h1>Upload Torrent</h1>
            <Form action ='' method='post'>
                <table border='0' style="padding-top: 5px;">
                    <tr>
                        <td>File torrent*: </td>
                        <td><div class="input-control text">
                                <input type="url" placeholder="Enter torrent's file url" name="url"/>
                                <span class="helper"></span>
                            </div></td>
                    </tr>
                    <tr>
                        <td>Name*: </td>
                        <td><div class="input-control text">
                                <input type="text" placeholder="Enter torrent's name" name="torrentName"/>
                                <span class="helper"></span>
                            </div></td>
                    </tr>
                    <tr>
                        <td>Description: </td>
                        <td><div class="input-control textarea">
                                <textarea name="torrentDescription"></textarea>

                            </div></td>
                    </tr>
                    <tr>
                        <td>Category: </td>
                        <td><div class="input-control select">
                                <select name="torrentCategory">
                                    <option value="Anime">Anime</option>
                                    <option value="Books">Books</option>
                                    <option value="Games">Games</option>
                                    <option value="Movies">Movies</option>
                                    <option value="Music">Music</option>
                                    <option value="Other">Other</option>
                                    <option value="TV">TV</option>
                                </select>
                            </div></td>
                    </tr>
                </table>
                <br><input type ='submit' value='Upload'>
                <input type='reset' value='Reset'>
            </form>
        </div>
        <%
            String torrentName = "", torrentDescription = "", torrentTime = "";
            response.setContentType("text/html;charset=UTF-8");
            try {
                if (request.getParameter("torrentName") != null) {
                    try {
                        torrentName = request.getParameter("torrentName").trim();
                        torrentDescription = request.getParameter("torrentDescription").trim();
                        Date time = new Date();
                        torrentTime = new SimpleDateFormat("yyyy-MM-dd").format(time);
                    } catch (Exception e) {
                        out.println("<h3>Error: " + e.getMessage() + "</h3>");
                    }
                }
            } catch (Exception e) {
                out.println("<div style=\"width:800px; margin:0 auto; padding-top: 250px\"><h3>" + e.getMessage() + "</h3></div>");
            } finally {
                //out.close();
            }
        %>
        <Trackertag:UploadTagHandler torrentName="<%=torrentName%>" torrentDescription="<%=torrentDescription%>" torrentTime="<%=torrentTime%>"/>
    </body>
</html>
